package com.itheima.travel.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.travel.dao.RouteDao;
import com.itheima.travel.domain.Route;
import com.itheima.travel.service.RouteService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteServiceImpl implements RouteService {

    @Autowired
    private RouteDao routeDao;

    @Override
    public PageInfo<Route> findByPageByCid(int cid, int pageNum, String rname) {
        PageHelper.startPage(pageNum, 5);
        List<Route> routeList = routeDao.findByPageByCid(cid, rname);
        PageInfo<Route> pageInfo = new PageInfo<>(routeList);
        return pageInfo;
    }

    @Override
    public Route findRouteByRid(Integer rid) {
        return routeDao.findRouteByRid(rid);
    }

    @Override
    public PageInfo<Route> findByPage(int pageNum, String pMin, String pMax, String rname) {
        PageHelper.startPage(pageNum,5);
        List<Route> routeList = routeDao.findByPage(pMin, pMax, rname);
        PageInfo<Route> pageInfo = new PageInfo<>(routeList);
        return pageInfo;
    }
}
